package com.xayq.orap.security;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.xayq.orap.mapper.UserMapper;
import com.xayq.orap.model.User;

@Service("myUserDetailsService")
public class MyUserDetailsService implements UserDetailsService{
	//Logger log=Logger.getLogger(MyUserDetailsService.class);
	@Autowired
	private UserMapper userMapper;
	@Autowired  
    private MessageSource messageSource;
	
	//登录验证
	public UserDetails loadUserByUsername(String name)
			throws UsernameNotFoundException {
		User user = userMapper.loadUserByUsername(name);
		if(user==null){
            throw new UsernameNotFoundException(this.messageSource.getMessage("UserDetails.userNotFound",new Object[]{name},null));
		}
		return user;
	}
}
